package com.nannybear.View;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nannybear.R;

/**
 * \brief Calendar screen
 * \author Audrey LOISEAU
 * \date 4-05-2015
 */

/********************************* COPYRIGHT *********************************
 * Copyright (c) 2015, Audrey LOISEAU and Benjamin LANCINOT.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *************************************************************************************/

public class CalendarScreen extends Screen {
    /********** DECLARATIONS **********/
    // Variables
    private RelativeLayout pop_up_calendar, calendar_grid, add_layout, delete_layout;
    private LinearLayout listItem;
    private ImageButton prevMonth, nextMonth;
    private Button popUp_add, popUp_cancel;
    private TextView currentMonth, day, day_pop_up, event_value;
    private GridView calendarView;
    private Button dayButton;
    private ImageButton hour_up_start, hour_down_start, part_up_start, hour_up_end, hour_down_end, part_up_end, color_btn, min_up_start, min_down_start, min_up_end, min_down_end;
    private TextView txt_hour_start, txt_part_start, txt_hour_end, txt_part_end, txt_min_start, txt_min_end;
    private EditText edit_event;
    private String icon;
    private ImageView event_leisure, event_health, event_other;

    /************ METHODS ************/
    /**
     * \brief Constructor
     */
    public CalendarScreen(){
        super(R.layout.calendar_screen, false, false);
    }

    /**
     * \brief Change the visibility of the pop up layout
     * \param date  The date
     */
    public void displayPopUp(String date){
        if(date != null) {
            day_pop_up.setText(date);
            calendar_grid.setVisibility(View.GONE);
            pop_up_calendar.setVisibility(View.VISIBLE);
            listItem.setVisibility(View.VISIBLE);
            delete_layout.setVisibility(View.GONE);
            popUp_add.setText("Add");
            popUp_cancel.setText("Cancel");
        }
        else{
            calendar_grid.setVisibility(View.VISIBLE);
            listItem.setVisibility(View.GONE);
            add_layout.setVisibility(View.GONE);
            pop_up_calendar.setVisibility(View.GONE);
        }
    }

    /**
     * \brief Change the popUp to add an event
     */
    public void displayPopUpAdd(){
        txt_hour_start.setText("12");
        txt_min_start.setText("00");
        txt_part_start.setText("a.m");
        txt_hour_end.setText("12");
        txt_min_end.setText("00");
        txt_part_end.setText("a.m");
        day_pop_up.setText("Add an event");
        icon = "health";
        color_btn.setBackgroundResource(R.drawable.red_cross);
        edit_event.setText("");
        calendar_grid.setVisibility(View.GONE);
        pop_up_calendar.setVisibility(View.VISIBLE);
        listItem.setVisibility(View.GONE);
        add_layout.setVisibility(View.VISIBLE);
    }

    /**
     * \brief Change the popUp to delete an event
     * \param event The title of the event
     */
    public void deleteEvent(String event){
        day_pop_up.setText("Delete an event");
        event_value.setText(event);
        listItem.setVisibility(View.GONE);
        delete_layout.setVisibility(View.VISIBLE);
        popUp_add.setText("Yes");
        popUp_cancel.setText("No");
    }

    /**
     * \brief Change the icon
     */
    public void changeIconEvent(){
        // Health to leisure
        if(icon.equals("health")){
            icon = "leisure";
            color_btn.setBackgroundResource(R.drawable.tree);
        }
        // Leisure to other
        else if(icon.equals("leisure")){
            icon = "other";
            color_btn.setBackgroundResource(R.drawable.star);
        }
        // Other to health
        else if(icon.equals("other")){
            icon = "health";
            color_btn.setBackgroundResource(R.drawable.red_cross);
        }
    }

    /**
     * \brief Show the view
     * \param thresholdTemp The value of temperature threshold
     * \param thresholdHum  The value of humidity threshold
     */
    public void display(int thresholdTemp, int thresholdHum){
        icon = "health"; //red_cross
        getTempButton().setBackgroundResource(getTempDrawable()[thresholdTemp]);
        getHumidityButton().setBackgroundResource(getHumDrawable()[thresholdHum]);
        getCalendarButton().setBackgroundResource(R.drawable.calendar_active);
    }

    /**
     * \brief Close the view (empty)
     */
    public void close(){
    }

    /*********** ACCESSORS ***********/
    /**
     * \brief Get method for the current month (TextView)
     */
    public TextView getCurrentMonth() {
        return currentMonth;
    }

    /**
     * \brief Get method for the calendar view
     */
    public GridView getCalendarView() {
        return calendarView;
    }

    /**
     * \brief Get method for the day (TextView)
     */
    public TextView getDay() {
        return day;
    }

    /**
     * \brief Get method for the day button
     */
    public Button getDayButton() {
        return dayButton;
    }

    /**
     * \brief Get method for the add_layout
     */
    public RelativeLayout getAdd_layout() {
        return add_layout;
    }

    /**
     * \brief Get method for the list view of event
     */
    public LinearLayout getListItem() {
        return listItem;
    }

    /**
     * \brief Get method for the start hour time (TextView)
     */
    public TextView getTxt_hour_start() {
        return txt_hour_start;
    }

    /**
     * \brief Get method for the day part start (TextView)
     */
    public TextView getTxt_part_start() {
        return txt_part_start;
    }

    /**
     * \brief Get method for the end hour time (TextView)
     */
    public TextView getTxt_hour_end() {
        return txt_hour_end;
    }

    /**
     * \brief Get method for the day part end (TextView)
     */
    public TextView getTxt_part_end() {
        return txt_part_end;
    }

    /**
     * \brief Get method for the minute start
     */
    public TextView getTxt_min_start() {
        return txt_min_start;
    }

    /**
     * \brief Get method for the delete_layout
     */
    public RelativeLayout getDelete_layout() {
        return delete_layout;
    }

    /**
     * \brief Set method for the edit text
     */
    public EditText getEdit_event() {
        return edit_event;
    }

    /**
     * \brief Get method for the icon other
     */
    public ImageView getEvent_other() {
        return event_other;
    }

    /**
     * \brief Get method for the icon health
     */
    public ImageView getEvent_health() {
        return event_health;
    }

    /**
     * \brief Set method for the icon
     */
    public String getIcon() {
        return icon;
    }

    /**
     * \brief Get method for the event leisure
     */
    public ImageView getEvent_leisure() {
        return event_leisure;
    }

    /**
     * \brief Set method for the previous month
     */
    public TextView getTxt_min_end() {
        return txt_min_end;
    }

    /**
     * \brief Set method for the previous month
     */
    public void setPrevMonth(ImageButton prevMonth) {
        this.prevMonth = prevMonth;
    }

    /**
     * \brief Set method for the next month
     */
    public void setNextMonth(ImageButton nextMonth) {
        this.nextMonth = nextMonth;
    }

    /**
     * \brief Set method for the current month
     */
    public void setCurrentMonth(TextView currentMonth) {
        this.currentMonth = currentMonth;
    }

    /**
     * \brief Set method for the day
     */
    public void setDay(TextView day) {
        this.day = day;
    }

    /**
     * \brief Set method for the day button
     */
    public void setDayButton(Button dayButton) {
        this.dayButton = dayButton;
    }

    /**
     * \brief Set method for the calendar view
     */
    public void setCalendarView(GridView calendarView) {
        this.calendarView = calendarView;
    }

    /**
     * \brief Set method for the pop up calendar
     */
    public void setPop_up_calendar(RelativeLayout pop_up_calendar) {
        this.pop_up_calendar = pop_up_calendar;
    }

    /**
     * \brief Set method for the calendar grid view
     */
    public void setCalendar_grid(RelativeLayout calendar_grid) {
        this.calendar_grid = calendar_grid;
    }

    /**
     * \brief Set method for the day pop up
     */
    public void setDay_pop_up(TextView day_pop_up) {
        this.day_pop_up = day_pop_up;
    }

    /**
     * \brief Set method for the add button on the pop up
     */
    public void setPopUp_add(Button popUp_add) {
        this.popUp_add = popUp_add;
    }

    /**
     * \brief Set method for cancel button on the pop up
     */
    public void setPopUp_cancel(Button popUp_cancel) {
        this.popUp_cancel = popUp_cancel;
    }

    /**
     * \brief Set method for the list layout
     */
    public void setListItem(LinearLayout listItem) {
        this.listItem = listItem;
    }

    /**
     * \brief Set method for the add_layout
     */
    public void setAdd_layout(RelativeLayout add_layout) {
        this.add_layout = add_layout;
    }

    /**
     * \brief Set method for the hour start up button
     */
    public void setHour_up_start(ImageButton hour_up_start) {
        this.hour_up_start = hour_up_start;
    }

    /**
     * \brief Set method for the hour start down button
     */
    public void setHour_down_start(ImageButton hour_down_start) {
        this.hour_down_start = hour_down_start;
    }

    /**
     * \brief Set method for the part start up button
     */
    public void setPart_up_start(ImageButton part_up_start) {
        this.part_up_start = part_up_start;
    }

    /**
     * \brief Set method for the hour end up button
     */
    public void setHour_up_end(ImageButton hour_up_end) {
        this.hour_up_end = hour_up_end;
    }

    /**
     * \brief Set method for the hour end down button
     */
    public void setHour_down_end(ImageButton hour_down_end) {
        this.hour_down_end = hour_down_end;
    }

    /**
     * \brief Set method for the part end up button
     */
    public void setPart_up_end(ImageButton part_up_end) {
        this.part_up_end = part_up_end;
    }

    /**
     * \brief Set method for the icon button
     */
    public void setColor_btn(ImageButton color_btn) {
        this.color_btn = color_btn;
    }

    /**
     * \brief Set method for the hour start
     */
    public void setTxt_hour_start(TextView txt_hour_start) {
        this.txt_hour_start = txt_hour_start;
    }

    /**
     * \brief Set method for the part start
     */
    public void setTxt_part_start(TextView txt_part_start) {
        this.txt_part_start = txt_part_start;
    }

    /**
     * \brief Set method for the hour end
     */
    public void setTxt_hour_end(TextView txt_hour_end) {
        this.txt_hour_end = txt_hour_end;
    }

    /**
     * \brief Set method for the part end
     */
    public void setTxt_part_end(TextView txt_part_end) {
        this.txt_part_end = txt_part_end;
    }

    /**
     * \brief Set method for the edit text
     */
    public void setEdit_event(EditText edit_event) {
        this.edit_event = edit_event;
    }

    /**
     * \brief Set method for the minute start up button
     */
    public void setMin_up_start(ImageButton min_up_start) {
        this.min_up_start = min_up_start;
    }

    /**
     * \brief Set method for the minute start down up
     */
    public void setMin_down_start(ImageButton min_down_start) {
        this.min_down_start = min_down_start;
    }

    /**
     * \brief Set method for the minute start
     */
    public void setTxt_min_start(TextView txt_min_start) {
        this.txt_min_start = txt_min_start;
    }

    /**
     * \brief Set method for the minute end
     */
    public void setTxt_min_end(TextView txt_min_end) {
        this.txt_min_end = txt_min_end;
    }

    /**
     * \brief Set method for the minute end up button
     */
    public void setMin_up_end(ImageButton min_up_end) {
        this.min_up_end = min_up_end;
    }

    /**
     * \brief Set method for the minute end down button
     */
    public void setMin_down_end(ImageButton min_down_end) {
        this.min_down_end = min_down_end;
    }

    /**
     * \brief Set method for the event leisure
     */
    public void setEvent_leisure(ImageView event_leisure) {
        this.event_leisure = event_leisure;
    }

    /**
     * \brief Set method for the icon health
     */
    public void setEvent_health(ImageView event_health) {
        this.event_health = event_health;
    }

    /**
     * \brief Set method for the icon other
     */
    public void setEvent_other(ImageView event_other) {
        this.event_other = event_other;
    }

    /**
     * \brief Set method for the delete_layout
     */
    public void setDelete_layout(RelativeLayout delete_layout) {
        this.delete_layout = delete_layout;
    }

    /**
     * \brief Set method for the event (TextView)
     */
    public void setEvent_value(TextView event_value) {
        this.event_value = event_value;
    }
}